package utils

import (
	"regexp"
	"strconv"
)

const contentRe = `<img.+?alt='|"__shop__Bucket__fileId__([0-9]+).*?>`

// 贪婪提取富文本字符串的图片id
func FindAllEditorFileIds(content string) (fileIds []uint) {
	subMatch := regexp.MustCompile(contentRe).FindAllSubmatch([]byte(content), -1)
	if content == "" || len(subMatch) == 0 {
		return fileIds
	}
	for _, value := range subMatch {
		fileId, err := strconv.Atoi(string(value[1]))
		if err == nil {
			fileIds = append(fileIds, uint(fileId))
		}
	}
	return fileIds
}
